/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import vo.VOProblem;

/**
 *
 * @author sbaldrich
 */
@Entity
@Table(name = "problem")
@NamedQueries(
{
    @NamedQuery(name = "Problem.findAll", query = "SELECT p FROM Problem p"),
    @NamedQuery(name = "Problem.findByIdProblem", query = "SELECT p FROM Problem p WHERE p.idProblem = :idProblem"),
    @NamedQuery(name = "Problem.findByProblemCode", query = "SELECT p FROM Problem p WHERE p.problemCode = :problemCode"),
    @NamedQuery(name = "Problem.findByName", query = "SELECT p FROM Problem p WHERE p.name = :name"),
    @NamedQuery(name = "Problem.findByTime", query = "SELECT p FROM Problem p WHERE p.time = :time"),
    @NamedQuery(name = "Problem.findByDifficulty", query = "SELECT p FROM Problem p WHERE p.difficulty = :difficulty"),
    @NamedQuery(name = "Problem.findBySubmissions", query = "SELECT p FROM Problem p WHERE p.submissions = :submissions"),
    @NamedQuery(name = "Problem.findByAccepted", query = "SELECT p FROM Problem p WHERE p.accepted = :accepted"),
    @NamedQuery(name = "Problem.findByVisible", query = "SELECT p FROM Problem p WHERE p.visible = :visible")
})
public class Problem implements Serializable
{

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idProblem")
    private Integer idProblem;
    @Basic(optional = false)
    @Column(name = "problemCode")
    private String problemCode;
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    @Basic(optional = false)
    @Lob
    @Column(name = "description")
    private String description;
    @Basic(optional = false)
    @Column(name = "time")
    private int time;
    @Basic(optional = false)
    @Column(name = "difficulty")
    private int difficulty;
    @Basic(optional = false)
    @Column(name = "submissions")
    private int submissions;
    @Basic(optional = false)
    @Column(name = "accepted")
    private int accepted;
    @Column(name = "visible")
    private Boolean visible;
    @JoinTable(name = "problem_keyword", joinColumns =
    {
        @JoinColumn(name = "idProblem", referencedColumnName = "idProblem")
    }, inverseJoinColumns =
    {
        @JoinColumn(name = "idKeyword", referencedColumnName = "idKeyword")
    })
    @ManyToMany
    private List<Keyword> keywordList;
    @JoinColumn(name = "idContest", referencedColumnName = "idContest")
    @ManyToOne(optional = false)
    private Contest contest;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "problem")
    private List<Submission> submissionList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "problem")
    private List<Testcase> testcaseList;

    public Problem()
    {
    }

    public Problem(Integer idProblem)
    {
        this.idProblem = idProblem;
    }

    public Problem(Integer idProblem, String problemCode, String name, String description, int time, int difficulty, int submissions, int accepted)
    {
        this.idProblem = idProblem;
        this.problemCode = problemCode;
        this.name = name;
        this.description = description;
        this.time = time;
        this.difficulty = difficulty;
        this.submissions = submissions;
        this.accepted = accepted;
    }

    public Problem(VOProblem vo)
    {
        this(vo.getIdProblem(), vo.getProblemCode(), vo.getName(), vo.getDescription(),
                vo.getTime(), vo.getDifficulty(), vo.getAccepted(), vo.getSubmissions());
    }

    public Integer getIdProblem()
    {
        return idProblem;
    }

    public void setIdProblem(Integer idProblem)
    {
        this.idProblem = idProblem;
    }

    public String getProblemCode()
    {
        return problemCode;
    }

    public void setProblemCode(String problemCode)
    {
        this.problemCode = problemCode;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getDescription()
    {
        return description;
    }

    public void setDescription(String description)
    {
        this.description = description;
    }

    public int getTime()
    {
        return time;
    }

    public void setTime(int time)
    {
        this.time = time;
    }

    public int getDifficulty()
    {
        return difficulty;
    }

    public void setDifficulty(int difficulty)
    {
        this.difficulty = difficulty;
    }

    public int getSubmissions()
    {
        return submissions;
    }

    public void setSubmissions(int submissions)
    {
        this.submissions = submissions;
    }

    public int getAccepted()
    {
        return accepted;
    }

    public void setAccepted(int accepted)
    {
        this.accepted = accepted;
    }

    public Boolean getVisible()
    {
        return visible;
    }

    public void setVisible(Boolean visible)
    {
        this.visible = visible;
    }

    public List<Keyword> getKeywordList()
    {
        return keywordList;
    }

    public void setKeywordList(List<Keyword> keywordList)
    {
        this.keywordList = keywordList;
    }

    public Contest getContest()
    {
        return contest;
    }

    public void setContest(Contest contest)
    {
        this.contest = contest;
    }

    public List<Submission> getSubmissionList()
    {
        return submissionList;
    }

    public void setSubmissionList(List<Submission> submissionList)
    {
        this.submissionList = submissionList;
    }

    public List<Testcase> getTestcaseList()
    {
        return testcaseList;
    }

    public void setTestcaseList(List<Testcase> testcaseList)
    {
        this.testcaseList = testcaseList;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (idProblem != null ? idProblem.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Problem))
        {
            return false;
        }
        Problem other = (Problem) object;
        if ((this.idProblem == null && other.idProblem != null) || (this.idProblem != null && !this.idProblem.equals(other.idProblem)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "entities.Problem[idProblem=" + idProblem + "]";
    }

    public VOProblem getVO()
    {
        return new VOProblem(this);
    }
}
